#include "ClientPacket.h"

CClientPacket::CClientPacket(void)
{
}

CClientPacket::CClientPacket(DWORD len) : CSerialBuffer(len)
{

}

CClientPacket::~CClientPacket(void)
{
}

void CClientPacket::Init(WORD wOpcode, DWORD dwFlags)
{
	Clear();

	*this << (DWORD)0;
	*this << (WORD)wOpcode;
	*this << (DWORD)dwFlags;
}

void CClientPacket::Init(const BYTE* buf, int nBufLen)
{
	Clear();

	Append(buf, nBufLen);
}

DWORD CClientPacket::GetPacketSize() const
{
	return ReadDWORD(0);
}

WORD CClientPacket::GetCmd() const
{
	return ReadWORD(sizeof(DWORD));
}

DWORD CClientPacket::GetFlags() const
{
	return ReadWORD(sizeof(DWORD)+sizeof(WORD));
}

void CClientPacket::MakePacket()
{
	assert(Size() >= sizeof(DWORD) + sizeof(WORD) + sizeof(DWORD));
	// WriteDWORD(Size()-sizeof(DWORD), 0);
	WriteDWORD(Size(), 0);
}
